def before(request,kargs):
    print 'before'
def after(request,kargs):
    print'after'
def filter(before_func,after_func):#filter的参数吧def before和after带入到了这个函数中
    def outer(main_func): #mian_func 是吧index及参数带入
        def wrapper(request,kargs):
            before_result = before_func(request,kargs)
            if(before_result != None):
                return before_result
            main_result = main_func(request,kargs)
            if(main_result !=None):
                return main_result;
            after_result = after_func(request,kargs)
            if(after_result !=None):
                return after_result;
        return wrapper
    return outer
@filter(before,after)#启动程序后,解释器先运行这个，将before和after带入filter。
def index(request,kargs):
    print 'index'
index('req','alex')#首先这个才是启动程序的command